<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Go Transfer Docs</title>
        <style>
            body {
                font-family: 'Courier New', Courier, monospace;
            }
            p {
                margin-left: 2em;
            }
        </style>
    </head>

    <body>
        <h1>Local Transfer API Docs</h1>

        <h2>1. Version</h2>
        <p>Go Transfer</p>
        <p>协议：MIT License</p>
        <p>作者: @Illusionna</p>
        <p>隶属: Jarvis Engineering Tool</p>
        <p>GitHub：https://github.com/Illusionna/LocalTransfer</p>
        <p>主页: https://orzzz.net</p>
        <p>邮箱: www@orzzz.net</p>

        <h2>2. Notice</h2>
        <p>API 必须在无密码登录状态下才可以使用! 默认就是无密码状态. 如果你需要密码进行登录, 则无法调用 API.</p>
        <p>(e.g.) >>> goer.exe  --login  123456</p>

        <h2>3. API</h2>
    
        <h3>3.1. /api/file-list/</h3>
        <p>(e.g. 获取共享根目录) >>> curl  http://localhost:8888/api/file-list?path=.</p>
        <p>(e.g. 获取共享根目录下的字体子文件夹) >>> curl  http://localhost:8888/api/file-list?path=./fonts</p>
        <p>(禁止访问父级目录) >>> curl  http://localhost:8888/api/file-list?path=./fonts/../</p>
        <p>(禁止访问服务器目录) >>> curl  "http://localhost:8888/api/file-list?path=C:/User/Zolio Marling/Desktop"</p>
        <p>返回值：</p>
<pre><code>
        [
            {
                "FileName": ". .",
                "FileSize": "",
                "FileIcon": "NULL",
                "ModifiedTime": ""
            },
            {
                "FileName": "README.txt",
                "FileSize": "103 B",
                "FileIcon": "txt",
                "ModifiedTime": "2025-01-18 22:35:17"
            },
            {
                "FileName": "en.ttf",
                "FileSize": "112.88 KB",
                "FileIcon": "ttf",
                "ModifiedTime": "2025-01-18 22:35:17"
            },
            {
                "FileName": "zh.ttf",
                "FileSize": "17.67 MB",
                "FileIcon": "ttf",
                "ModifiedTime": "2025-01-18 22:35:17"
            }
        ]
</code></pre>

        <h3>3.2. /api/share/</h3>
        <p>(e.g. 下载文件) >>> wget  http://localhost:8888/api/share/fonts/README.txt</p>
        <p>注意: 当使用 "-login" 参数设置登录密码后, wget 下载会失败, 重定向到登录页面.</p>

        <h3>3.3. /api/file-property/</h3>
        <p>(e.g. 查看文件的属性 >>> Python requests 库代码)</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/file-property/',
            json = [
                {'Path': 'Ollava-Browser-App.exe'},
                {'Path': './fonts/zh.ttf'},
                {'Path': './fonts/en.ttf'},
                {'Path': './fonts/README.txt'}
            ]
        )

        print(response.text)
</code></pre>
        <p>返回值：{"FileCount":4,"SumSize":"20.19 MB","ModifiedTime":"2025-01-25 19:51:03","AgoTime":"半小时前（星期六）"}</p>

        <h3>3.4. /api/edit-announcement/</h3>
        <p>(e.g. 编辑公告栏) 其中 "Content" 是 HTML 格式的富文本格式.</p>
<pre><code>
        import requests
            
        response = requests.post(
            url = 'http://localhost:8888/api/edit-announcement/',
            json = {'Content': '大家请注意, 这是太空漫游 &lt;img src="https://www.orzzz.net/directory/about/SpaceOdyssey.png"&gt;'}
        )
</code></pre>

        <h3>3.5. /api/announcement-content/</h3>
        <p>(e.g. 查看公告栏内容) >>> curl  http://localhost:8888/api/announcement-content/</p>
        <p>返回值：{"Content": "大家请注意, 这是太空漫游 \u003cimg src=\"https://www.orzzz.net/directory/about/SpaceOdyssey.png\"\u003e"}</p>

        <h3>3.6. /api/upload-file/</h3>
        <p>(e.g. 上传文件) 其中 "CurrentDir" 代表上传文件到服务器的某个目录, "RelativePath" 代表在 "CurrentDir" 目录基础上的相对路径.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/upload-file/',
            files = {'File': open('A:/Illusionna/Desktop/HelloWorld.txt', mode='rb')},
            data = {
                'RelativePath': './demo/HelloWorld.txt',
                'CurrentDir': './ABC'
            }
        )
</code></pre>

        <h3>3.7. /api/delete-file/</h3>
        <p>(e.g. 删除文件) 其中禁止删除父级目录文件或服务器绝对路径文件.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/delete-file/',
            json = [
                {'Path': './ABC/demo/HelloWorld.txt'},              # 允许
                {'Path': '../ABC/demo/HelloWorld.txt'},             # 无效
                {'Path': '../HelloWorld.txt'},                      # 无效
                {'Path': 'A:/Illusionna/Desktop/HelloWorld.txt'}    # 无效
            ]
        )
</code></pre>

        <h3>3.8. /api/batch-download/</h3>
        <p>(e.g. 归档压缩文件) 其中 "CurrentDir" 代表相对于 "Path" 的归档路径, 例如下面第一个示例的 Archive.zip 内容树结构.</p>
<pre><code>
        Archive
        |
        |── Ollava-Browser-App.exe
        |—— fonts
            |—— en.ttf
            |—— README.txt
            |—— zh.ttf
</code></pre>

<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/batch-download/',
            json = [
                {'Path': './project/dst/Ollava-Browser-App.exe', 'CurrentDir': './project/dst'},
                {'Path': './project/dst/fonts/zh.ttf', 'CurrentDir': './project/dst'},
                {'Path': './project/dst/fonts/en.ttf', 'CurrentDir': './project/dst'},
                {'Path': './project/dst/fonts/README.txt', 'CurrentDir': './project/dst'}
            ]
        )
        
        with open('./Archive.zip', mode='wb') as f:
            f.write(response.content)
</code></pre>

        <p>当然, 简单起见, 你可以忽略文件结构树.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/batch-download/',
            json = [
                {'Path': './project/dst/Ollava-Browser-App.exe'},
                {'Path': './project/dst/fonts/zh.ttf'},
                {'Path': './project/dst/fonts/en.ttf'},
                {'Path': './project/dst/fonts/README.txt'}
            ]
        )

        with open('./Archive.zip', mode='wb') as f:
            f.write(response.content)
</code></pre>

        <p>这会显示如下的结构.</p>
<pre><code>
        Archive
        |
        |── project
            |── dst
                |── Ollava-Browser-App.exe
                |—— fonts
                    |—— en.ttf
                    |—— README.txt
                    |—— zh.ttf
</code></pre>

        <p>同样的, 禁止归档下载路径越界文件.</p>
        <p>(e.g.) >>> {'Path': '../../Illusionna的隐私.txt'}</p>

        <h3>3.9. /api/make-directory/</h3>
        <p>(e.g. 创建一个文件夹) 在 "CurrentDir" 目录下创建递归子文件夹 "Path".</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/make-directory/',
            json = {'Path': 'demo-folder/abc', 'CurrentDir': '.'}
        )
</code></pre>

        <h3>3.10. /api/move-file/</h3>
        <p>(e.g. 移动文件) 将 "Path" 位置文件移动到 "CurrentDir" 目录, 禁止移动越界文件.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/move-file/',
            json = [
                {'Path': './fonts/README.txt', 'CurrentDir': '.'},
                {'Path': './fonts/en.ttf', 'CurrentDir': './demo-folder'}
            ]
        )
</code></pre>

        <h3>3.11. /api/rename-file/</h3>
        <p>(e.g. 重命名某单个文件) 禁止越界重命名.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/rename-file/',
            json = [
                {'OldName': './fonts/README.txt', 'NewName': './fonts/README.md'}
            ]
        )
</code></pre>

        <p>(e.g. 批量重命名多个文件) 将 "CurrentDir" 目录下的 "OldName" 文件(夹)以 "Prefix" 前缀和 "Suffix" 后缀进行重命名, 禁止越界改名.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/rename-file/',
            json = [
                {'OldName': 'en.ttf', 'CurrentDir': './fonts', 'Prefix': '字体', 'Suffix': '号'},
                {'OldName': 'zh.ttf', 'CurrentDir': './fonts', 'Prefix': '字体', 'Suffix': '号'},
                {'OldName': 'README.md', 'CurrentDir': './fonts', 'Prefix': '文档', 'Suffix': ''}
            ]
        )
</code></pre>
        <p>批量重命名效果类似: "./fonts/字体1号.ttf"、"./fonts/字体2号.ttf"、"./fonts/文档3.md".</p>

        <h3>3.12. /api/copy-file/</h3>
        <p>(e.g. 拷贝文件) 将 "Path" 位置的文件拷贝到 "CurrentDir" 目录位置, 禁止越界复制粘贴.</p>
<pre><code>
        import requests

        response = requests.post(
            url = 'http://localhost:8888/api/copy-file/',
            json = [
                {'Path': './fonts/字体1号.ttf', 'CurrentDir': '.'},
                {'Path': './fonts/字体2号.ttf', 'CurrentDir': '.'}
            ]
        )
</code></pre>

        <h2>4. Support</h2>
        <p>如果你觉得该项目对你有所帮助, 非常欢迎 GitHub (<a href="https://github.com/Illusionna/LocalTransfer" target="_blank">https://github.com/Illusionna/LocalTransfer</a>) 关注 star : )</p>

    </body>
</html>